package com.hzx.controller;

import com.hzx.service.SeckillService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SeckillController {

    @Autowired
    SeckillService seckillService;

    @HystrixCommand(fallbackMethod = "seckillFail")
    @RequestMapping("/seckill")
    public int seckill(@RequestParam("aId") int aId, @RequestParam("uId") int uId) {
        return seckillService.seckill(aId, uId);
    }

    /**
     * 抢票熔断的备选方法
     * @return -6：服务器异常
     */
    private int seckillFail(@RequestParam("aId") int aId, @RequestParam("uId") int uId){
        return -6;
    }
}
